package com.bruce.pattern.creational.simplefactory;

/**
 * <pre>
 *    简单工厂
 * </pre>
 * Created by bruce on 2018/10/24 19:55
 */
public class VideoFactory {

    public Video newVideo(String type) {
        if ("java".equalsIgnoreCase(type)) {
            return new JavaVideo();
        } else if ("python".equalsIgnoreCase(type)) {
            return new PythonVideo();
        }
        return null;
    }

    //反射实现简单工厂
    public Video getVideo(Class<? extends Video> c) {
        try {
            return c.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }


}
